using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Verifications;
using Pixysoft.Weblications.Sango.Constant;
using Pixysoft.Weblications.Sango.Formular;

namespace Pixysoft.Weblications.Sango.Battle
{
    class SkilLSingleTwiceSkill : InstantBattleSkill, IBattleSkill
    {
        public SkilLSingleTwiceSkill()
            : base(SkillTypecodeCollection.SKILL_10_ATTACK_TWICE)
        {
        }

        public void apply(BattleActionHistory action, IBattleSkillAttack skillattack, Battler attacker, BattleTeam attacks, BattleTeam defenses)
        {
            Battler defenser = defenses.getOneApplier(attacker);

            if (defenser == null)
                return;

            if (!BattleFormular.skillAttackHit(attacker, defenser))
            {
                attacker.clearPowervalue();

                BattleActionItemHistory actionItem = action.createItem(defenser, BattleActionItemTypecodeCollection.ATTACK_MISS);
                actionItem.Attacker = (attacker.createHistory());
                actionItem.Defenser = (defenser.createHistory());
                return;
            }
            else
            {
                long hpValue = BattleFormular.skillAttackDamage(attacker, defenser, attacker.getPowervalue());


                defenser.reduceHpPointValue(hpValue);
                BattleActionItemHistory actionItem = action.createItem(defenser, BattleActionItemTypecodeCollection.ATTACK_SUCCEED);
                actionItem.Defenser = (defenser.createHistory());
                actionItem.Attacker = (attacker.createHistory());

                defenser.reduceHpPointValue(hpValue);
                actionItem = action.createItem(defenser, BattleActionItemTypecodeCollection.ATTACK_SUCCEED);
                actionItem.Defenser = (defenser.createHistory());
                actionItem.Attacker = (attacker.createHistory());

                attacker.clearPowervalue();
            }
        }



        public bool hasPowervalue()
        {
            return true;
        }
    }
}